package com.nanhang.auth.controller;

import com.nanhang.auth.Uo.UserUo;
import com.nanhang.auth.entity.UserLogin;
import com.nanhang.auth.service.IUserservice;
import com.nanhang.auth.service.Tokenservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class Logiccontroll {

    @Autowired
    private IUserservice userservice;
    @Autowired
    private Tokenservice tokenservice;


    @GetMapping("/login")
    public R login(@RequestBody UserUo uo){
        UserLogin loginUser = userservice.findUser(uo);
        if(loginUser != null){
            Map<String,Object> map = tokenservice.createToken(loginUser);
            return R.ok(map,"登录成功");
        }
        return R.fail("登录失败！");
    }
}
